/*
 * Copyright 2009 Eat Local Food, LLC
 * Copyright (c) 2007 osCommerce (this file was written after
 * code review of osCommerce).
 *
 * This file is part of gwtCommerce.
 *
 * gwtCommerce is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * gwtCommerce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gwtCommerce.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.elf.gwt.common.client.model;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.json.client.JSONObject;

public class CountryModel extends AbstractModel
{
	protected int id;
	protected int addressFormatId = 0;
	protected String addressFormat;
	protected String addressSummary;
	protected String isoCode2;
	protected String isoCode3;
	protected String name;
	protected List<ZoneModel> zones;
	
	public CountryModel()
	{
		id = -1;
		addressFormatId = 0;
		name = "";
		isoCode2 = "";
		isoCode3 = "";
		addressFormat = "";
		addressSummary = "";
		zones = new ArrayList<ZoneModel>();
	}

	public CountryModel(JSONObject jsonObject)
	{
		id = convertToInteger(jsonObject, "id");
		addressFormatId = convertToInteger(jsonObject,"address_format_id");
		name = convertToString(jsonObject,"name");
		isoCode2 = convertToString(jsonObject,"iso_code_2");
		isoCode3 = convertToString(jsonObject,"iso_code_3");
		addressFormat = convertToString(jsonObject,"address_format");
		addressSummary = convertToString(jsonObject,"address_summary");
		zones = new ArrayList<ZoneModel>();
	}

	public void update(CountryModel model)
	{
		id = model.getId();
		addressFormatId = model.getAddressFormatId();
		name = model.getName();
		isoCode2 = model.getIsoCode2();
		isoCode3 = model.getIsoCode3();
		addressFormat = model.getAddressFormat();
		addressSummary = model.getAddressSummary();
		zones = model.getZones();
	}

	public int getId() {
		return id;
	}
	
	public int getAddressFormatId() {
		return addressFormatId;
	}

	public String getName() {
		return name;
	}

	public String getIsoCode2() {
		return isoCode2;
	}

	public String getIsoCode3() {
		return isoCode3;
	}

	public String getAddressFormat() {
		return addressFormat;
	}

	public String getAddressSummary() {
		return addressSummary;
	}

	public List<ZoneModel> getZones() {
		return zones;
	}

	public void addZone(ZoneModel zone) {
		zones.add(zone);
	}
}
